﻿namespace GoodAdmin.System;

/// <summary>
/// 系统菜单表
/// </summary>
[SugarTable(tableName: "Sys_Menu", "系统菜单表")]
public class SysMenu: BaseTreeEntity<SysMenu>
{
    /// <summary>
    /// 路由标题 
    ///</summary>
    [SugarColumn(ColumnName = "Title", ColumnDescription = "路由标题", Length = 64)]
    public virtual string Title { get; set; }
    /// <summary>
    /// 路由名称 
    ///</summary>
    [SugarColumn(ColumnName = "Name", ColumnDescription = "路由名称", Length = 64, IsNullable = true)]
    public string Name { get; set; }
    /// <summary>
    /// 编码 
    ///</summary>
    [SugarColumn(ColumnName = "Code", ColumnDescription = "编码", Length = 256, IsNullable = true)]
    public virtual string Code { get; set; }
    /// <summary>
    /// 分类 
    ///</summary>
    [SugarColumn(ColumnName = "Category", ColumnDescription = "分类", Length = 256, IsNullable = true)]
    public string Category { get; set; }
    /// <summary>
    /// 菜单类型 
    ///</summary>
    [SugarColumn(ColumnName = "MenuType", ColumnDescription = "菜单类型", Length = 256, IsNullable = true)]
    public virtual string MenuType { get; set; }
    /// <summary>
    /// 路径 
    ///</summary>
    [SugarColumn(ColumnName = "Path", ColumnDescription = "路径", IsNullable = true,Length =256)]
    public virtual string Path { get; set; }
    /// <summary>
    /// 组件 
    ///</summary>
    [SugarColumn(ColumnName = "Component", ColumnDescription = "组件", Length = 256, IsNullable = true)]
    public string Component { get; set; }
    /// <summary>
    /// 图标 
    ///</summary>
    [SugarColumn(ColumnName = "Icon", ColumnDescription = "图标", Length = 32, IsNullable = true)]
    public virtual string Icon { get; set; }
    /// <summary>
    /// 颜色 
    ///</summary>
    [SugarColumn(ColumnName = "Color", ColumnDescription = "颜色", Length = 32, IsNullable = true)]
    public string Color { get; set; }

    /// <summary>
    /// 是否缓存
    /// </summary>
    [SugarColumn(ColumnName = "IsKeepAlive", ColumnDescription = "是否缓存")]
    public bool IsKeepAlive { get; set; } = true;

    /// <summary>
    /// 是否固定在标签页中
    /// </summary>
    [SugarColumn(ColumnName = "IsAffix", ColumnDescription = "是否固定在标签页中")]
    public bool IsAffix { get; set; } = false;
    /// <summary>
    /// 是否全屏
    /// </summary>
    [SugarColumn(ColumnName = "IsFull", ColumnDescription = "是否全屏")]
    public bool IsFull { get; set; } = false;
    /// <summary>
    /// 是否隐藏
    /// </summary>
    [SugarColumn(ColumnName = "IsHide", ColumnDescription = "是否隐藏")]
    public bool IsHide { get; set; } = false;

    /// <summary>
    /// 是否外链
    /// </summary>
    [SugarColumn(ColumnName = "IsLink", ColumnDescription = "是否外链")]
    public bool IsLink { get; set; }

    /// <summary>
    /// 链接地址
    /// </summary>
    [SugarColumn(ColumnName = "OutLink", ColumnDescription = "链接地址", Length = 256, IsNullable = true)]
    public string Link { get; set; }
    /// <summary>
    /// 排序码 
    ///</summary>
    [SugarColumn(ColumnName = "SortCode", ColumnDescription = "排序码", IsNullable = true)]
    public int SortCode { get; set; } = 999;
    /// <summary>
    /// 系统标识字段
    /// </summary>
    [SugarColumn(ColumnDescription = "系统标识", Length = 32, IsNullable = true)]
    public string SystemMark { get; set; }

    [SugarColumn(ColumnDescription = "ActiveMenu", Length = 256, IsNullable = true)]
    public string ActiveMenu { get; set; }


    [SugarColumn(IsIgnore = true)]
    public MenuMeta Meta { get; set; }
}

/// <summary>
/// 菜单Meta配置
/// </summary>
public class MenuMeta
{
    /// <summary>
    /// 标题
    /// </summary>
    public string Title { get; set; }

    /// <summary>
    /// 图标
    /// </summary>
    public string Icon { get; set; }

    /// <summary>
    /// 是否隐藏
    /// </summary>
    public bool IsHide { get; set; }

    /// <summary>
    /// 是否缓存
    /// </summary>
    public bool IsKeepAlive { get; set; }

    /// <summary>
    /// 是否全屏
    /// </summary>
    public bool IsFull { get; set; }
    public bool IsLink { get; set; }
    public string Link { get; set; }
    /// <summary>
    /// 菜单是否固定在标签页中
    /// </summary>
    public bool IsAffix { get; set; }
    public string ActiveMenu { get; set; }
}



/// <summary>
/// 配置菜单对象映射
/// </summary>
public class SysMenuMapper : IRegister
{
    public void Register(TypeAdapterConfig config)
    {
        config.ForType<SysMenu, MenuInfo>()
            .Map(t => t.Name, o => o.Name)
            .Map(t => t.Code, o => o.Code)
            .Map(t => t.Category, o => o.Category)
            .Map(t => t.MenuType, o => o.MenuType)
            .Map(t => t.Path, o => o.Path)
            .Map(t => t.Component, o => o.Component)
            .Map(t => t.SystemMark, o => o.SystemMark);
        config.ForType<SysMenu, MenuMeta>()
            .Map(t => t.Title, o => o.Title)
            .Map(t => t.Icon, o => o.Icon)
            .Map(t => t.IsHide, o => o.IsHide)
            .Map(t => t.IsKeepAlive, o => o.IsKeepAlive)
            .Map(t => t.IsLink,o => o.IsLink)
            .Map(t => t.Link,o => o.Link)
            .Map(t => t.ActiveMenu, o => o.ActiveMenu)
            .Map(t=>t.IsFull,o=>o.IsFull)
            .Map(it=>it.IsAffix,o=>o.IsAffix);
    }
}

public class ApiResource
{
    public string Group { get; set; }
    public string Controller { get; set; }
    /// <summary>
    /// 接口描述
    /// </summary>
    public string ApiName { get; set; }


    /// <summary>
    /// 路由名称
    /// </summary>
    public string ApiRoute { get; set; }


    /// <summary>
    /// 资源名称
    /// </summary>
    public string ResourceName { get; set; }

    /// <summary>
    /// 是否需要数据范围
    /// </summary>
    public bool IsDataScope { get; set; }
}